package com.mc.lp.database.entity.helper;

import java.util.Date;

import com.mc.lp.database.entity.SportsRecordEntity;
import com.mc.lp.shared.util.DateUtil;
import com.mc.lp.shared.vo.SportsRecordVO;
/*
 * @author aphanda
 * @date Sep 28, 2014
 * @time 12:42:57 AM
 */

public class SportsRecordHelper implements IEntityHelper<SportsRecordEntity, SportsRecordVO> {

	@Override
	public SportsRecordVO getVO(SportsRecordEntity entity) {
		SportsRecordVO vo = new SportsRecordVO();

		vo.setDated(DateUtil.convertDate2StringDate(entity.getDated(), "dd-MMMM-yyyy"));
		vo.setGradeId(entity.getGradeId());
		vo.setMedal(entity.getMedal());
		vo.setCompetitionLevel(entity.getCompetitionLevel());
		vo.setNewRow(false);
		vo.setRanking(entity.getRanking());
		vo.setRemarks(entity.getRemarks());
		vo.setSid(entity.getId());
		vo.setSportId(entity.getSportId());
		vo.setSportsAttachmentId(entity.getSportsAttachmentId());
		vo.setAttributeWeightage(entity.getAttributeWeightage());
		return vo;
	}

	@Override
	public SportsRecordEntity getEntity(SportsRecordVO vo) {
		SportsRecordEntity entity = new SportsRecordEntity();
		setEntity(vo, entity);
		return entity;
	}

	@Override
	public void setEntity(SportsRecordVO vo, SportsRecordEntity entity) {
		if (!vo.isNewRow())
			entity.setId(vo.getSid());
		
		if(vo.isNewRow())
			entity.setCreatedDate(new Date());
		
		
		entity.setCompetitionLevel(vo.getCompetitionLevel());
		entity.setDated(new Date());
		entity.setGradeId(vo.getGradeId());
		entity.setMedal(vo.getMedal());
		entity.setModifiedDate(new Date());
		entity.setRanking(vo.getRanking());
		entity.setRemarks(vo.getRemarks());
		entity.setSportId(vo.getSportId());
		entity.setSportsAttachmentId(vo.getSportsAttachmentId());
		entity.setAttributeWeightage(vo.getAttributeWeightage());
	}

}
